package wsepForum.test.presistance;

import wsepForum.common.elements.AForumElement;
import wsepForum.common.elements.SearchResult;
import wsepForum.common.elements.User;
import wsepForum.common.elements.AForumElement.ForumElementType;
import wsepForum.persistance.IPersistentHandler;

import java.util.*;

/**
 * A stub implementation of the persistent interface, for testings
 * @author Oren Ben-Haim
 *
 */
public class PersistentImplStub implements IPersistentHandler {

	private Hashtable<String, User> users;
	private Hashtable<Integer,AForumElement> forumEl;

	public PersistentImplStub(){
		this.users = new Hashtable<String, User>();
		this.forumEl = new Hashtable<Integer,AForumElement>();

		this.users.put("user1", new User("user1","user1",User.UserType.MEMBER));
		this.users.put("user2", new User("user2","user2",User.UserType.MODERATOR));
		this.users.put("user3", new User("user3","user3",User.UserType.ADMIN));
	}

	/* (non-Javadoc)
	 * @see wsepForum.persistance.IPersistentHandler#getForumElement(double)
	 */
	@Override
	public AForumElement getForumElement(int forumElementID, ForumElementType type) {
		return this.forumEl.get(forumElementID);
	}

	/* (non-Javadoc)
	 * @see wsepForum.persistance.IPersistentHandler#getUser(java.lang.String)
	 */
	@Override
	public User getUser(String strUserName) {
		return this.users.get(strUserName);
	}

	/* (non-Javadoc)
	 * @see wsepForum.persistance.IPersistentHandler#login(java.lang.String, java.lang.String)
	 */
	@Override
	public boolean login(String strUserName, String strPassword){
		return strPassword.equals(strUserName) && this.users.containsKey(strUserName);
	}

	/* (non-Javadoc)
	 * @see wsepForum.persistance.IPersistentHandler#setForumElement(double, wsepForum.common.elements.AForumElement)
	 */
	@Override
	public int setForumElement(int parentID, ForumElementType type, AForumElement element){
		this.forumEl.put(element.getElementID(), element);
		return element.getElementID();

	}

	/* (non-Javadoc)
	 * @see wsepForum.persistance.IPersistentHandler#setUser(wsepForum.common.elements.User)
	 */
	@Override
	public boolean setUser(User user) {
		boolean userExist = this.users.contains(user);
		this.users.put(user.getUserName(), user);
		return userExist;

	}

	@Override
	public AForumElement deleteForumElement(int elementID, ForumElementType type) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public boolean deleteUser(String strUserName) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public Vector<SearchResult> searchByAuthor(String authorName) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Vector<SearchResult> searchByContent(String sentence) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Vector<SearchResult> searchByDate(Date from, Date to) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void close() {
		// TODO Auto-generated method stub

	}

	@Override
	public double[] getMessageCountStatistics(Date date) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public double[] getUserCountStatistics(Date date) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public double[] getUserMessagePerDay(Date date, String userName) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Vector<String> getUsernameList() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void logout(String username) {
		// TODO Auto-generated method stub

	}

	@Override
	public void clearDB() throws Exception {
		// TODO Auto-generated method stub

	}

	@Override
	public boolean initDB() throws Exception {
		// TODO Auto-generated method stub
		return false;
	}

}
